package com.teach.cms.api;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.teach.cms.entity.ArticleType;
import com.teach.cms.service.ArticleTypeService;


 /**
 * <pre>
 * - 文章类别前端API控制器
 * Author : J.L.Zhou
 * E-Mail : 12020042
 * Tel : 151 1104 7708
 * Date : 2022-10-24 23:48
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 */
@RestController
@RequestMapping("/cms/article-type")
public class ArticleTypeApi {

	@Autowired
	private ArticleTypeService articleTypeService;



	@GetMapping("list")
	public Object list() throws Exception {
		return articleTypeService.list();
	}

	@GetMapping("page")
	public Object page(Page<ArticleType> page) throws Exception {
		return articleTypeService.page(page);
	}

	@GetMapping("{id}")
	public Object id(@PathVariable("id") Integer articleTypeId) {
		return articleTypeService.getById(articleTypeId);
	}

	@PostMapping
	public void add(@RequestBody ArticleType articleType) {
			articleTypeService.save(articleType);
	}

	@PutMapping
	public void update(@RequestBody ArticleType articleType) {
		articleTypeService.updateById(articleType);
	}

	@DeleteMapping("{id}")
	public void delete(@PathVariable("id") Integer articleTypeId) {
		articleTypeService.removeById(articleTypeId);
	}

	@DeleteMapping("ids")
	public void delete(Integer[] articleTypeId) {
		articleTypeService.removeByIds(Arrays.asList(articleTypeId));
	}

}
